void Load_ATT(unsigned char);

enum ATT
{
  ATT_IF1_PRM,
  ATT_IF1_PRD,
  ATT_IF2_PRM
};

void Load_ATT_542(ATT att, unsigned char data)
{
  unsigned int mask=0x80;
  data<<=2;  
  switch(att) // LE = 0
  {
    case ATT_IF1_PRM:
      PORTD&=~(1<<PD7);  
      break;
    case ATT_IF1_PRD:
      PORTB&=~(1<<PB0);  
      break;
    case ATT_IF2_PRM:
      PORTC&=~(1<<PC5);         
      break;      
  }
  PORTB&=~(1<<PB2);  //sclk=0
  __delay_cycles(10);
  while(mask)
  {
    if(data & mask) { PORTB&=~(1<<PB1); }  else { PORTB|=(1<<PB1); }
    __delay_cycles(10);
    PORTB|=(1<<PB2);  //sclk=1
    __delay_cycles(10);
    mask >>=1;
    PORTB&=~(1<<PB2); //sclk=0
  }
  PORTD|=(1<<PD7);   // LE = 1
  PORTB|=(1<<PB0);   // LE = 1
  PORTC|=(1<<PC5);   // LE = 1
};

void Load_ATT_629(ATT att, unsigned char data)
{
  unsigned int mask=0x08;
  switch(att) // LE = 0
  {
    case ATT_IF1_PRM:
      PORTD&=~(1<<PD7);  
      break;
    case ATT_IF1_PRD:
      PORTB&=~(1<<PB0);  
      break;
    case ATT_IF2_PRM:
      PORTC&=~(1<<PC5);         
      break;      
  }
  PORTB&=~(1<<PB2);  //sclk=0
  __delay_cycles(10);
  while(mask)
  {
    if(data & mask) { PORTB&=~(1<<PB1); }  else { PORTB|=(1<<PB1); }
    __delay_cycles(10);
    PORTB|=(1<<PB2);  //sclk=1
    __delay_cycles(10);
    mask >>=1;
    PORTB&=~(1<<PB2); //sclk=0
  }
  PORTD|=(1<<PD7);   // LE = 1
  PORTB|=(1<<PB0);   // LE = 1
  PORTC|=(1<<PC5);   // LE = 1
};


